package com.leo;

import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

/**
 * @ClassName ScrollPaneDemo
 * @Description
 * @Author wangss
 * @date 2020.05.26 20:27
 * @Version 1.0
 */
public class ScrollPaneDemo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        AnchorPane anchorPane = new AnchorPane();
        anchorPane.setStyle("-fx-background-color: #e7eeea");
        Scene scene = new Scene(anchorPane);

        VBox box = new VBox();

        HBox hBox = new HBox();
        for (int i = 0; i <= 10; i++) {
            hBox.getChildren().add(new Button("button" + i));
        }

        VBox vBox = new VBox();
        for (int i = 0; i <= 10; i++) {
            vBox.getChildren().add(new Button("button" + i));
        }

        box.getChildren().addAll(hBox, vBox);

        ScrollPane scrollPane = new ScrollPane();
        scrollPane.setContent(box);
        scrollPane.setPrefWidth(300d);
        scrollPane.setPrefHeight(300d);

        anchorPane.getChildren().add(scrollPane);

        primaryStage.setScene(scene);
        primaryStage.setTitle("spinner");
        primaryStage.setWidth(625d);
        primaryStage.setHeight(500d);
        primaryStage.setResizable(false);
        primaryStage.show();

        scrollPane.hvalueProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {

            }
        });

        scrollPane.vvalueProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {

            }
        });
    }
}
